package com.ds.infrastructure.hyperspace.console.service.impl;

import com.ds.infrastructure.hyperspace.console.dao.dao.TbReleaseContainerConfigDao;
import com.ds.infrastructure.hyperspace.console.entity.enums.TbPublicEnum;
import com.ds.infrastructure.hyperspace.console.entity.page.TbPageWhere;
import com.ds.infrastructure.hyperspace.console.entity.table.TbReleaseContainerConfig;
import com.ds.infrastructure.hyperspace.console.entity.where.TbCustomWhere;
import com.ds.infrastructure.hyperspace.console.service.inf.IReleaseContainerConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: yaozhendong
 * @create: 2019-09-28 15:25
 **/

@Service
public class ReleaseContainerConfigService implements IReleaseContainerConfigService {
    @Autowired
    TbReleaseContainerConfigDao tbReleaseContainerConfigDao;

    @Override
    public int save(TbReleaseContainerConfig record) {
        return tbReleaseContainerConfigDao.insertSelective(record);
    }

    @Override
    public int update(TbReleaseContainerConfig record) {
        return tbReleaseContainerConfigDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public TbReleaseContainerConfig get(Long id) {
        TbReleaseContainerConfig entity = tbReleaseContainerConfigDao.selectByPrimaryKey(id);
        if (entity != null && TbPublicEnum.GMD_IS_DEL.NO.code.equals(entity.getGmtIsDeleted())) {
            return entity;
        }
        return null;
    }

    @Override
    public int delete(Long id) {
        TbReleaseContainerConfig item = new TbReleaseContainerConfig();
        item.setId(id);
        item.setGmtIsDeleted(TbPublicEnum.GMD_IS_DEL.YES.code);
        return update(item);
    }

    @Override
    public List<TbReleaseContainerConfig> getList(TbReleaseContainerConfig where, TbCustomWhere customWhere, TbPageWhere pageWhere) {
        return tbReleaseContainerConfigDao.selectListForPage(where, customWhere, pageWhere);
    }

    @Override
    public int getTotal(TbReleaseContainerConfig where, TbCustomWhere customWhere) {
        return tbReleaseContainerConfigDao.selectListForPageCount(where, customWhere);
    }

    @Override
    public TbReleaseContainerConfig selectOne(TbReleaseContainerConfig where, TbCustomWhere customWhere) {
        List<TbReleaseContainerConfig> itemList = tbReleaseContainerConfigDao.selectListForPage(where, customWhere, TbPageWhere.newPage4OnlyOne());
        return itemList.stream().findFirst().orElseGet(() -> null);
    }
}
